import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

///////////////////////////////////////////////////////// DrawingArea
class PLMouseManager implements MouseListener, MouseMotionListener {

	PLEndPointsReceiver mReceiver = null;

	Point mBegin = null;
	
    //=================================================== constructor
    public PLMouseManager(PLEndPointsReceiver receiver) {
	mReceiver = receiver;
    }

	public void StartListening(Canvas canvas) {
		canvas.addMouseListener(this); 
		canvas.addMouseMotionListener(this); 		
	}

	public void StopListening(Canvas canvas) {
		canvas.removeMouseListener(this); 
		canvas.removeMouseMotionListener(this); 		
	}

	public void Shutdown() {
		mReceiver = null;
	}

	public void mousePressed(MouseEvent evt) {
		PLDebug.Info("In the mouseDown"); 
		//Where the mouse went down is the start 

		//position of the shape to be drawn

		mBegin = new Point(evt.getPoint().x,evt.getPoint().y);
	}
	
	public void mouseDragged(MouseEvent evt) {
		if (mReceiver != null && mBegin != null) {
			Point endpos = new Point(evt.getPoint().x,evt.getPoint().y);
			mReceiver.NotifyIntermediate(mBegin, endpos);
		}
	}

	public void mouseReleased(MouseEvent evt) {    
		PLDebug.Info("Inside mouseReleased"); 

		if (mReceiver != null && mBegin != null) {
			Point endpos = new Point(evt.getPoint().x,evt.getPoint().y);
			mReceiver.NotifyFinal(mBegin, endpos);
			mBegin = null;
		}
	}

	//Mouse Down i.e. Left mouse button is down
	
	public void mouseMoved(MouseEvent e) {		
	}

	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub		
	}

	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}    
}

